﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:Controls="clr-namespace:MahApps.Metro.Controls"
                    xmlns:Converters="clr-namespace:MahApps.Metro.Converters">

    <Converters:ToUpperConverter x:Key="ToUpperConverter" />
    <Converters:ThicknessBindingConverter x:Key="ThicknessBindingConverter" />

    <Style x:Key="MetroGroupBox"
           TargetType="{x:Type GroupBox}">
        <Setter Property="Margin"
                Value="5" />
        <Setter Property="Padding"
                Value="5" />
        <Setter Property="SnapsToDevicePixels"
                Value="True" />
        <Setter Property="Foreground"
                Value="{DynamicResource BlackBrush}" />
        <Setter Property="Background"
                Value="{DynamicResource AccentColorBrush}" />
        <Setter Property="BorderBrush"
                Value="{DynamicResource AccentColorBrush}" />
        <Setter Property="BorderThickness"
                Value="1" />
        <Setter Property="Controls:ControlsHelper.HeaderFontSize"
                Value="{DynamicResource ContentFontSize}" />
        <Setter Property="Controls:GroupBoxHelper.HeaderForeground"
                Value="{x:Null}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type GroupBox}">
                    <Grid x:Name="GroupBoxRoot">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>
                        <Border x:Name="HeaderSite"
                                Grid.Row="0"
                                Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                UseLayoutRounding="True"
                                BorderThickness="{TemplateBinding BorderThickness}">
                            <ContentPresenter x:Name="HeaderContent"
                                              Margin="{TemplateBinding Padding}"
                                              UseLayoutRounding="False"
                                              Content="{TemplateBinding Header}"
                                              ContentTemplate="{TemplateBinding HeaderTemplate}"
                                              ContentTemplateSelector="{TemplateBinding HeaderTemplateSelector}"
                                              ContentStringFormat="{TemplateBinding HeaderStringFormat}"
                                              TextElement.FontSize="{TemplateBinding Controls:ControlsHelper.HeaderFontSize}"
                                              TextElement.FontStretch="{TemplateBinding Controls:ControlsHelper.HeaderFontStretch}"
                                              TextElement.FontWeight="{TemplateBinding Controls:ControlsHelper.HeaderFontWeight}"
                                              RecognizesAccessKey="True">
                                <TextElement.Foreground>
                                    <MultiBinding Converter="{x:Static Converters:BackgroundToForegroundConverter.Instance}">
                                        <Binding Mode="OneWay"
                                                 Path="Background"
                                                 RelativeSource="{RelativeSource TemplatedParent}" />
                                        <Binding Mode="OneWay"
                                                 Path="(Controls:GroupBoxHelper.HeaderForeground)"
                                                 RelativeSource="{RelativeSource TemplatedParent}" />
                                    </MultiBinding>
                                </TextElement.Foreground>
                            </ContentPresenter>
                        </Border>
                        <Border Grid.Row="1"
                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                UseLayoutRounding="True"
                                Background="Transparent"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=BorderThickness, Converter={StaticResource ThicknessBindingConverter}, ConverterParameter={x:Static Converters:IgnoreThicknessSideType.Top}}">
                            <ContentPresenter UseLayoutRounding="False"
                                              Margin="{TemplateBinding Padding}"
                                              Content="{TemplateBinding Content}"
                                              ContentTemplate="{TemplateBinding ContentTemplate}"
                                              Cursor="{TemplateBinding Cursor}" />
                        </Border>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="Controls:ControlsHelper.PreserveTextCase"
                                 Value="False">
                            <Setter TargetName="HeaderContent"
                                    Property="Content"
                                    Value="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=Header, Mode=OneWay, Converter={StaticResource ToUpperConverter}}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>
